<template>

  <div style="width: 100%;height: 100vh;" class="view-box f-column-Wcenter">

    <div class="form-box ">
      <h3 style="border-bottom: #ccc 2px solid;padding-bottom: 30px;">对标项目总资金&首发价计算</h3>
      <div class="form ">
        <el-form ref="ruleFormZ" :rules="rulesZ" :hide-required-asterisk="true" @submit.native.prevent
          @keyup.enter.native="stepsBtn('ruleFormZ')" label-position="top" :model="ruleFormZ">
          <div class="f-row-between" style="width: 600px;"><span>项目方公司名称：{{details.company}}</span> <span>对标商品名称：{{details2.assetName}}</span></div>

          <div class="f-row-between" style="width: 600px;margin-top: 20px;"><span>总资金计算</span></div>
          <div class="f-row-Hcenter " style="width: 100%;margin-top: 20px;">
            <div class="f-row-Hcenter" style="margin-left: 20px;margin-bottom: 21px;">
              <div class="f-row-Hcenter"><span>𝛧</span> </div>
              <el-input style="margin-left: 20px;" v-model="ruleFormZ.amountPrice" maxlength="30" placeholder=""></el-input>
            </div>
            <el-form-item prop="good_price" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>=</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleFormZ.good_price" maxlength="30" placeholder="对标商品单价"></el-input>
              </div>
            </el-form-item>
            <el-form-item prop="float_rate_k" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>x</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleFormZ.float_rate_k" maxlength="30" placeholder="K(浮动系数)"></el-input>
              </div>
            </el-form-item>
            <el-form-item prop="compare_good_total" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>x</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleFormZ.compare_good_total" maxlength="30" placeholder="上链对标商品数量"></el-input>
              </div>
            </el-form-item>
            <el-form-item prop="float_rate_r" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>x</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleFormZ.float_rate_r" maxlength="30" placeholder="λ(浮动系数)"></el-input>
              </div>
            </el-form-item>
            <el-button type="primary" plain style="margin-left: 30px;margin-top: -20px;" @click="onAmountPriceZ">执行运算</el-button>
          </div>
        </el-form>
        <span style="color: #CCCCCC;">系数参考值： Κ=1.22， λ=1.35 具体参数值需确认而定</span>
        <div class="f-row-between" style="width: 600px;margin-top: 50px;"><span>首发价计算</span></div>
        <el-form ref="ruleFormP" :rules="rulesP" :hide-required-asterisk="true" @submit.native.prevent
          @keyup.enter.native="stepsBtn('ruleFormP')" label-position="top" :model="ruleFormP">
          <div class="f-row-Hcenter " style="width: 100%;margin-top: 20px;">
            <div class="f-row-Hcenter" style="margin-left: 20px;margin-bottom: 21px;">
              <div class="f-row-Hcenter"><span>P</span> </div>
              <el-input style="margin-left: 20px;" v-model="ruleFormP.amountPrice" maxlength="30" placeholder=""></el-input>
            </div>
            <el-form-item prop="good_price" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>=</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleFormP.good_price" maxlength="30" placeholder="对标商品单价"></el-input>
              </div>
            </el-form-item>
            <el-form-item prop="split_factor" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>x</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleFormP.split_factor" maxlength="30" placeholder="𝛕(拆分系数)"></el-input>
              </div>
            </el-form-item>
            <el-form-item prop="supply_demand_factor" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>x</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleFormP.supply_demand_factor" maxlength="30"
                  placeholder="𝜑(供求因子)"></el-input>
              </div>
            </el-form-item>
            <el-form-item prop="cost_factor" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>x</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleFormP.cost_factor" maxlength="30" placeholder=" 𝛛(成本因子)"></el-input>
              </div>
            </el-form-item>
            <el-form-item prop="market_factor" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>x</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleFormP.market_factor" maxlength="30" placeholder=" 𝝎(市场因子)"></el-input>
              </div>
            </el-form-item>
            <el-button type="primary" plain style="margin-left: 30px;margin-top: -20px;" @click="onAmountPriceP">执行运算</el-button>
          </div>
          <span style="color: #CCCCCC;">系数参考值： 𝛕=0.002， 𝜑=1.18， 𝛛=1.25， 𝝎=1.15 具体参数值需确认而定</span>

        </el-form>
        <el-form ref="ruleForm1" :rules="rulesZ" :hide-required-asterisk="true" @submit.native.prevent
          @keyup.enter.native="stepsBtn(-1)" label-position="top" :model="ruleForm1">
          <el-form-item prop="cocReportGroupId" style="margin-left: 20px;width: 100%;">
            <div class="f-row-between" style="width: 600px;margin-top: 20px;margin-bottom: 20px;"><span>上链资产评估报告</span></div>
            <el-upload class="upload-demo upload-li-w50" :action="url+'/platform/attachmentFile/add'" :data="{ userId: userId,type:'ISTO_appraisal_report' }"
              :on-remove="deleteFile_lv_shi" :on-success="uploadFile_lv_shi" multiple :limit="5">
              <el-button size="small" type="primary">选择文件</el-button>
              <div slot="tip" class="el-upload__tip">
                请上传jpg / jpeg / png / pdf文件，文件大小不超过10MB
              </div>
            </el-upload>
          </el-form-item>
        </el-form>
        <div>
          <el-button type="success" plain @click="stepsBtn(0)">驳回</el-button>
          <el-button type="success" plain @click="stepsBtn(1)">发布</el-button>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
  import serveApi from '@/api/serveApi.js'
  export default {
    name: "Authorization",
    data() {

      return {
        userInfo: '',
        userId: '',
        url: '',
        routeData: {},
        details:{},
        details2:{},
        query1: {
            id:0,
            applyIstoId :0
        },
        ruleFormZ: {
          amountPrice: '', //总资金计算
          good_price: '', //*number(query) 对标商品单价
          float_rate_k: '', //*number(query) 浮动系数K
          compare_good_total: '', //*number(query) 上链对标商品总量
          float_rate_r: '' //*number(query) 浮动系数R
        },
        rulesZ: {
          good_price: [{
            required: true,
            message: "请输入对标商品单价",
            trigger: "blur"
          }],
          float_rate_k: [{
            required: true,
            message: "请输入K(浮动系数)",
            trigger: "blur"
          }],
          compare_good_total: [{
            required: true,
            message: "请输入上链对标商品总量",
            trigger: "blur"
          }],
          float_rate_r: [{
            required: true,
            message: "请输入λ(浮动系数)",
            trigger: "blur"
          }]
        },
        ruleFormP: {
          amountPrice: '',
          good_price: '', // *number(query) 对标商品单价
          split_factor: '', // *number(query) 拆分系数
          supply_demand_factor: '', //*number(query) 供求因子
          cost_factor: '', //*number(query) 成本因子
          market_factor: '' //*number(query) 市场因子
        },
        rulesP: {
          good_price: [{
            required: true,
            message: "请输入对标商品单价",
            trigger: "blur"
          }], // *number(query) 对标商品单价
          split_factor: [{
            required: true,
            message: "请输入拆分系数",
            trigger: "blur"
          }], // *number(query) 拆分系数
          supply_demand_factor: [{
            required: true,
            message: "请输入供求因子",
            trigger: "blur"
          }], //*number(query) 供求因子
          cost_factor: [{
            required: true,
            message: "请输入成本因子",
            trigger: "blur"
          }], //*number(query) 成本因子
          market_factor: [{
            required: true,
            message: "请输入市场因子",
            trigger: "blur"
          }] //*number(query) 市场因子
        },
        ruleForm1: {
          cocReportGroupId: '',
          id: '',
          startPrice: '',
          totalPrice: ''
        },
        rules1: {
          cocReportGroupId: [
            {
              required: true,
              message: "请上传估值文件",
              trigger: "blur"
            }
          ]
        }
      }
    },
    mounted() {
      let that = this;

      that.url = process.env.VUE_APP_BASE_API;
      this.userId = this.$store.state.userInfo.id;
      this.routeData = this.$route.query
      this.getDetails();
       this.getDetails2() ;
    },
    methods: {
      getDetails() {
         this.query1.id = this.routeData.id;
        serveApi.applySto_id(this.query1).then(res => {
          if (res.status == "0000") {
            if (res.data) {
              this.details = res.data;
            }
          } else {
            this.$message.error(res.message);
          }
        });
      },
      getDetails2() {
        this.query1.applyIstoId = this.routeData.applyIstoId;
        serveApi.applyIsto_id(this.query1).then(res => {
          if (res.status == "0000") {
            if (res.data) {
              this.details2 = res.data;
            }
          } else {
            that.$message.error(res.message);
          }
        });
      },
      stepsBtn(e) {
         this.ruleForm1.id=  this.routeData.applyIstoId;
        if (e == 0) {
          this.ruleForm1.status = 3;
          serveApi.applyIsto_applyIsto(this.ruleForm1).then(res => {
            if (res.data) {
                this.$message.success('驳回成功');

            } else {
              this.$message.error(res.message);
            }
          });
        } else {


          if (this.ruleFormZ.amountPrice <= 0) {
            this.$message.error('请运算总资金');
            return
          }
          if (this.ruleFormP.amountPrice <= 0) {
            this.$message.error('请运算首发价');
            return
          }
          this.ruleForm1.status = 2;
          this.ruleForm1.startPrice = this.ruleFormP.amountPrice;
          this.ruleForm1.totalPrice = this.ruleFormZ.amountPrice;
          this.ruleForm1.calBenchmark= this.ruleFormZ.amountPrice*2; //需提交的抵押资产价值
		   this.ruleForm1.cocReportGroupId = JSON.stringify( this.ruleForm1.cocReportGroupArr );
          this.$refs.ruleForm1.validate(valid => {
            if (valid) {
              serveApi.applyIsto_applyIsto(this.ruleForm1).then(res => {
                if (res.data) {
                    this.$message.success('发布成功');
                } else {
                  this.$message.error(res.message);
                }
              });
            }
          })
        }

      },

      deleteFile_lv_shi(response, file, fileList) {
        let index = this.ruleForm1.cocReportGroupArr.findIndex(function(student) {
          return student.name == response.name;
        })
        this.ruleForm1.cocReportGroupArr.splice(index, 1);
      },
      uploadFile_lv_shi(response, file, fileList) {
        this.ruleForm1.cocReportGroupArr = this.ruleForm1.cocReportGroupArr || [];
        response.data.name = file.name;
        this.ruleForm1.cocReportGroupArr.push(response.data);
		 this.$upload("ruleForm1", "cocReportGroupId");
      },
      onAmountPriceZ() {
        this.$refs.ruleFormZ.validate(valid => {
          if (valid) {
            serveApi.project_funds(this.ruleFormZ).then(res => {
              if (res.data) {
                this.ruleFormZ.amountPrice = res.data.project_total_funds;
                this.$message.success('运算成功');
              } else {
                this.$message.error(res.message);
              }
            });
          }
        })
      },
      onAmountPriceP() {
        this.$refs.ruleFormP.validate(valid => {
          if (valid) {
            serveApi.start_price(this.ruleFormP).then(res => {
              if (res.data) {
                this.ruleFormP.amountPrice = res.data.start_price;
                this.$message.success('运算成功');
              } else {

                this.$message.error(res.message);
              }
            });
          }
        })
      }



    }
  }
</script>

<style scoped lang="scss">
  /* 表单的lable */
  .el-form--label-top .el-form-item__label {
    float: none;
    display: inline-block;
    text-align: left;
    padding: 0;


    font-size: 14px;
    font-family: MicrosoftYaHei;
    color: #3B3734;
  }
</style>
<style scoped lang="scss">
  .view-box {
    background-color: #ece9e7;
  }

  h6 {
    height: 73px;
    font-size: 36px;
    font-family: MicrosoftYaHeiSemibold;
    color: #3B3734;
    line-height: 48px;
    letter-spacing: 1px;
    position: relative;

    &::after {
      content: '';
      width: 66px;
      position: absolute;
      border-bottom: 2px solid #007AFF;
      bottom: 0px;
      margin-top: 25px;
    }
  }

  .form-box {
    width: 95%;
    // height: 800px;
    background: #FFFFFF;
    box-shadow: 0px 0px 10px 0px rgba(178, 178, 178, 0.2);
    border-radius: 4px;
    margin-top: 47px;
    padding: 24px;
    margin-bottom: 50px;


  }

  .upload-demo {
    	width: 50%;
      button{
        width: 50%;
      }
  	.el-upload {

    	width: 100%;

  		.el-button {
  			height: 50px;
  			width: 100%;
  			background: transparent;
  			color: rgba(43, 139, 195, 1);
  			font-size: 14px;
  			border: 1px dashed #dddddd;
  		}
  	}

  	.el-upload__tip {
  		line-height: 20px;
  		color: rgba(153, 153, 153, 1);
  		font-size: 13px;

  		a {
  			color: rgba(43, 139, 195, 1);
  			cursor: pointer;
  		}
  	}
  }
</style>
